package com.clgc.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.clgc.eduservice.entity.EduStudent;
import com.clgc.eduservice.entity.KcbjStudent;
import com.clgc.eduservice.mapper.KcbjStudentMapper;
import com.clgc.eduservice.service.EduStudentService;
import com.clgc.eduservice.service.KcbjStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author cml
 * @create 2021/5/14 14:45
 */
@Service
public class KcbjStudentServiceImpl extends ServiceImpl<KcbjStudentMapper, KcbjStudent> implements KcbjStudentService {
    @Autowired
    EduStudentService eduStudentService;

    /**
     * 根据课程班级id获取属于该班级学生
     * @param kcbjId 课程班级id
     * @return
     */
    @Override
    public List<EduStudent> getStudentsByKcbjId(String kcbjId) {
        QueryWrapper<EduStudent> eduStudentQueryWrapper = new QueryWrapper<>();
        eduStudentQueryWrapper.select("id","name","sex","major_id","class_id")
                .inSql("id","select student_id from kcbj_student where kcbj_id = "+kcbjId);
        List<EduStudent> students = eduStudentService.list(eduStudentQueryWrapper);
        List<EduStudent> studentList = students.stream().sorted(Comparator.comparingInt(EduStudent::getId)).collect(Collectors.toList());
        return studentList;
    }


}
